import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/',
    redirect: '/workbench'
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/workbench',
    component: Layout,
    children: [{
      path: '', // 地址为空
      name: 'workbench',
      component: () => import('@/views/workbench/index'),
      meta: { title: '工作台', icon: 'el-icon-eleme' }
    }]
  },
  {
    path: '/park',
    component: Layout,
    name: 'park',
    meta: { title: '园区管理', icon: 'el-icon-office-building' },
    children: [
      {
        path: 'building',
        name: 'building',
        meta: { title: '楼宇管理' },
        component: () => import('@/views/park/Building.vue')
      },
      {
        path: 'enterprise',
        name: 'enterprise',
        meta: { title: '企业管理' },
        component: () => import('@/views/park/Enterprise.vue')
      },
      {
        path: 'addEnterprise',
        component: () => import('@/views/park/components/add-enterprise.vue'),
        hidden: true
      },
      {
        path: 'enterpriseDetail',
        component: () => import('@/views/park/components/enterprise-detail.vue'),
        hidden: true
      }]
  },
  {
    path: '/property',
    component: Layout,
    children: [{
      path: '', // 地址为空
      name: 'property',
      component: () => import('@/views/property/index'),
      meta: { title: '物业费管理', icon: 'el-icon-wallet' }
    }]
  },

  {
    path: '/parking',
    component: Layout,
    permission: 'parking',
    meta: { title: '行车管理', icon: 'el-icon-guide' },
    children: [
    //   {
    //   path: 'area',
    //   permission: 'parking:area',
    //   component: () => import('@/views/Car/CarArea'),
    //   meta: { title: '区域管理' }
    // },
      {
        path: 'card',
        permission: 'parking:card',
        component: () => import('@/views/car/CarCard'),
        meta: { title: '月卡管理' }
      },
      {
        path: 'cardAdd',
        component: () => import('@/views/car/add-card.vue'),
        hidden: true
      },
      {
        path: 'cardContinue',
        component: () => import('@/views/car/continue-card.vue'),
        hidden: true
      },
      //  {
      //   path: 'pay',
      //   permission: 'parking:payment',
      //   component: () => import('@/views/Car/CarPay'),
      //   meta: { title: '停车缴费管理' }
      // },
      {
        path: 'rule',
        permission: 'parking:rule',
        component: () => import('@/views/car/car-rule.vue'),
        meta: { title: '计费规则管理' }
      }
    ]
  },

  {
    path: '/sys',
    component: Layout,
    permission: 'sys',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [{
      path: 'role',
      permission: 'sys:role',
      component: () => import('@/views/system/Role.vue'),
      meta: { title: '角色管理' }
    }, {
      path: 'user',
      permission: 'sys:user',
      component: () => import('@/views/system/Employee.vue'),
      meta: { title: '员工管理' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
